<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui">

<ui:composition template="/WEB-INF/templates/BasicTemplate.xhtml">

	<ui:define name="content">

		<f:event type="preRenderView"
			listener="#{agentController.beforeSearchAgent}" />

		<div class="title ui-widget-header ui-corner-all">
			<h:panelGrid style="margin:auto;">
		BUSCAR AGENTES
		</h:panelGrid>

		</div>

		<h:form id="formSearch">
			<h:panelGrid style="margin:auto;">
				<h:panelGrid style="margin:auto;text-align:center;">
					<p:messages id="messages"></p:messages>
				</h:panelGrid>
				<h:panelGrid columns="3">

					<h:panelGrid columns="2">
						<p:outputLabel value="Nombre"></p:outputLabel>
						<p:inputText style="width: 250px;"
							value="#{agentController.agentName}"></p:inputText>

						<p:outputLabel value="Usuario"></p:outputLabel>
						<p:inputText style="width: 250px;"
							value="#{agentController.username}"></p:inputText>

						<p:outputLabel value="DNI"></p:outputLabel>
						<p:inputText style="width: 250px;"
							value="#{agentController.documentNumber}"></p:inputText>

					</h:panelGrid>
					<h:panelGrid columns="2">

						<p:outputLabel value="Codigo"></p:outputLabel>
						<p:inputText style="width: 180px;" value="#{agentController.code}"></p:inputText>

						<p:outputLabel value="Campaña"></p:outputLabel>
						<p:selectOneMenu id="campaigns" required="true"
							requiredMessage="Debe seleccionar campaña"
							value="#{agentController.campaignSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione..."></f:selectItem>
							<f:selectItem itemValue="t" itemLabel="Todos"></f:selectItem>
							<f:selectItem itemValue="s" itemLabel="Sin campaña"></f:selectItem>
							<f:selectItems value="#{agentController.campaigns}"></f:selectItems>
							<p:ajax listener="#{agentController.searchSupervisors}"
								update=":formSearch:supervisors :formSearch:messages"></p:ajax>
						</p:selectOneMenu>

						<p:outputLabel value="Supervisor"></p:outputLabel>
						<p:selectOneMenu id="supervisors"
							value="#{agentController.supervisorSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione..."></f:selectItem>
							<f:selectItem itemValue="t" itemLabel="Todos"></f:selectItem>
							<f:selectItem itemValue="s" itemLabel="Sin supervisor"></f:selectItem>
							<f:selectItems value="#{agentController.supervisors}"></f:selectItems>
						</p:selectOneMenu>

					</h:panelGrid>

					<h:panelGrid columns="2">

						<p:outputLabel value="Auto inicio"></p:outputLabel>
						<p:selectOneMenu id="autoready"
							value="#{agentController.autoreadySelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione..."></f:selectItem>
							<f:selectItem itemValue="true" itemLabel="Si"></f:selectItem>
							<f:selectItem itemValue="false" itemLabel="No"></f:selectItem>
						</p:selectOneMenu>
						
						<p:outputLabel value="Activo"></p:outputLabel>
						<p:selectOneMenu id="isActive"
							value="#{agentController.isActiveSelected}">
							<f:selectItem itemValue="" itemLabel="Seleccione..."></f:selectItem>
							<f:selectItem itemValue="true" itemLabel="Si"></f:selectItem>
							<f:selectItem itemValue="false" itemLabel="No"></f:selectItem>
						</p:selectOneMenu>

					</h:panelGrid>

				</h:panelGrid>
				<h:panelGrid columns="3" style="margin:auto;text-align:center;">
					<p:commandButton icon="ui-icon-search"
						actionListener="#{agentController.searchAgent}" value="Buscar"
						process="@form"
						update=":formSearch:searchTable :formSearch:messages">
					</p:commandButton>

					<p:spacer height="1" width="20"></p:spacer>

					<p:commandButton icon="ui-icon-plus" value="Agregar"
						action="add_agent.xhtml" immediate="true" update=":formSearch:messages">
					</p:commandButton>

				</h:panelGrid>
			</h:panelGrid>


			<p:dataTable value="#{agentController.agents}" var="a"
				rowKey="#{a.id}" paginator="true" rows="10" id="searchTable"
				selectionMode="single">

				<p:column headerText="NOMBRE">
					<h:outputText value="#{a.firstname} #{a.lastname}"></h:outputText>
				</p:column>

				<p:column headerText="USUARIO">
					<h:outputText value="#{a.username}"></h:outputText>
				</p:column>

				<p:column headerText="DNI">
					<h:outputText value="#{a.documentNumber}"></h:outputText>
				</p:column>

				<p:column headerText="CODIGO">
					<h:outputText value="#{a.code}"></h:outputText>
				</p:column>


				<p:column headerText="SUPERVISOR">
					<h:outputText
						value="#{a.supervisor.firstname} #{a.supervisor.lastname}"></h:outputText>
				</p:column>

				<p:column headerText="CAMPAÑAS">
					<h:outputText value="#{a.campaignsList}"></h:outputText>
				</p:column>

				<p:column headerText="AUTO INICIO">
					<h:outputText
						value="#{a.autoready==true ? 'Si' : (a.autoready==false ? 'No' : null)}"></h:outputText>
				</p:column>

				<p:column headerText="ACTIVO">
					<h:outputText
						value="#{a.isActive==true ? 'Si' : (a.isActive==false ? 'No' : null)}"></h:outputText>
				</p:column>

				<p:column style="width:4%">
					<p:commandButton id="selectButton" action="edit_agent.xhtml"
						icon="ui-icon-pencil" value="Editar" update=":formSearch:messages">
						<f:param name="agentId" value="#{a.id}"></f:param>
					</p:commandButton>
				</p:column>


			</p:dataTable>


		</h:form>
	</ui:define>

</ui:composition>
</html>
